package com.cjh.mybatis07.mapping;

import com.cjh.mybatis07.transaction.TransactionFactory;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.sql.DataSource;

/**
 * @Descripton 环境
 * @Author cjh
 * @Date 2023/5/29 10:40
 */
@Getter
@AllArgsConstructor
public final class Environment {
    /**
     * 环境id  ------<environment id="development">
     */
    private final String id;
    /**
     * 事务工厂
     */
    private final TransactionFactory transactionFactory;
    /**
     * 数据源
     */
    private final DataSource dataSource;

    public static class Builder{
        private String id;
        private TransactionFactory transactionFactory;
        private DataSource dataSource;

        public Builder(String id) {
            this.id = id;
        }

        public Builder transactionFactory(TransactionFactory transactionFactory){
            this.transactionFactory = transactionFactory;
            return this;
        }
        public Builder dataSource(DataSource dataSource){
            this.dataSource = dataSource;
            return this;
        }
        public String id(){
            return this.id;
        }
        public Environment build(){
            return  new Environment(this.id, this.transactionFactory, this.dataSource);
        }
    }
}
